The provided code has been used to generate data at the Ecoregion level for the Digital Observaty for Protected Areas The script uses Hansen et al. (2013) Global Forest Change map in conjunction with Google Earth Engine to calculate forest cover in years 2000 - 2012 for a given Ecoregion or Country
Global Forest Change map
GFC map is composed of several bands (layers). Each layer is a separate image that represents a different piece of information. Here we will focus on four of them: treecover2000: percentage of tree cover in the pixel. In other words, each pixel has value from 0 till 100, with 0 meaning no forest at all and 100 full forest cover loss: pixel has value 1 if loss ever occurred during the study period. gain: pixel has value 1 if gain ever occurred during the study period. lossyear: value of a pixel denotes in which year loss occurred, starting with 2000. In other words, if pixel has value 5, then it means that the deforestation event occurred in 2005.
Ecoregion statistics using GEE
calculate values
var display =true;var scale =100;// get the ecoregion fearurevar ecoregions = ee.FeatureCollection('ft:1GzN7apqS42eIZNUoS4uZoXyspckUuPh4dzLe0wMI','geometry');// filter the ecoregion fearurevar filterBiome = ecoregions.filterMetadata('BIOME','equals',12);var filterRealm = filterBiome.filterMetadata('REALM','equals','PA');// get the forest productvar gfcImage = ee.Image('UMD/hansen/global_forest_change_2015').clip(filterRealm);var treecover2000 = gfcImage.select('treecover2000');// set the treshold of the pixel value at 30 and multiply by the area of each pixel, this means that you consider only the pixels that are covered for more than 30% by treesvar treecover2000Area = treecover2000.gt(30).multiply(ee.Image.pixelArea());// sum number of pixels within the region selected (TREECOVER 2000) resoult in Havar forest2000 = treecover2000Area.divide(10000).reduceRegions({'collection': filterRealm,'reducer': ee.Reducer.sum(),'scale': scale
});var lossImage = gfcImage.select('loss');// set the treshold of the pixel value at 30 and multiply by the area of each pixel, this means that you consider only the pixels that are covered for more than 30% by treesvar lossArea = lossImage.multiply(treecover2000.gt(30)).multiply(ee.Image.pixelArea());// sum number of pixels within the region selected (LOSS 2015) resoult in Havar loss2012 = lossArea.divide(10000).reduceRegions({'collection': filterRealm,'reducer': ee.Reducer.sum(),'scale': scale
});var gainImage = gfcImage.select('gain');// calculate the area of the pixel without defining a treshold (according to GFW)var gainArea = gainImage.multiply(ee.Image.pixelArea());// sum number of pixels within the region selected (GAIN 2012) resoult in Havar gain2012 = gainArea.divide(10000).reduceRegions({'collection': filterRealm,'reducer': ee.Reducer.sum(),'scale': scale
});// export dataExport.table.toDrive({
collection: forest2000,
description:'cover',
fileFormat:'CSV'});Export.table.toDrive({
collection: gain2012,
description:'gain',
fileFormat:'CSV'});Export.table.toDrive({
collection: loss2015,
description:'loss',
fileFormat:'CSV'});// visualize on the map
Map.addLayer(lossImage.mask(lossImage),{'palette':'FF0000'},'Loss - red', display);
Map.addLayer(gainImage.mask(gainImage),{'palette':'0000FF'},'Gain - blue', display);
Map.centerObject(filterRealm);
Merge tables using Python
#A function to read forest area, gain and loss csv data and write out to single table#Requirements: numpy, os, operatorimport numpy as np
importosfromoperatorimport itemgetter
def read_me(file):
"""
Read the csv file, find ecoregion ID and associated data (forest area, loss, gain)
:param file: input file name to load
:return: ecoregion id and data (area, loss, gain)
"""#initiate the data listsid=[]
ddata =[]#open the csv filewithopen(file)as f:
lines = f.readlines()for line in lines[1:]:
data = line.split(',')
id_tmp = data[3]#load the idid.append(np.float(id_tmp))#load the datatry:
data_tmp = np.float(data[25])
ddata.append(data_tmp)exceptValueError:
data_tmp = np.float(data[24])
ddata.append(data_tmp)returnid, ddata
def do_all(folder):
"""
Do for all ecoregions; forest area, forest gain, forest loss.
Load all data for each ecoregion (and associated ID) and save as a single table.
:param folder: Define folder with all the data files
:return: Saved csv file.
"""#initiate the data listsid=[]
area =[]
loss =[]
gain =[]
unique_file_name =[]#find the seperate files for area (e.g. north am, europe)for _, _, files inos.walk(folder):
for f in files:
if"cover"in f:
un = f.split("cover")[0][:-1]if"loss"in f:
un = f.split("loss")[0][:-1]if"gain"in f:
un = f.split("gain")[0][:-1]
unique_file_name.append(un)for uni inset(unique_file_name):
for _, _, files inos.walk(folder):
for f in files:
#extend id and forest area list with eco_id and forest area columns from csvif"cover"in f and f.startswith(uni):
myfile =os.path.join(folder, f)print"Doing %s" %myfile
idd, ddata = read_me(myfile)#find the unique ids#some ids have multiple entries due to different geometries
unique_id =set(idd)id.extend(unique_id)#find the sum of all entries for a single idfor u in unique_id:
idx = np.where(np.array(idd)==u)[0]
area.extend([np.sum(itemgetter(*idx)(ddata))])#extend loss list with forest loss columns from csvif"loss"in f and f.startswith(uni):
myfile =os.path.join(folder, f)print"Doing %s" % myfile
_, ddata = read_me(myfile)for u in unique_id:
idx = np.where(np.array(idd)==u)[0]
loss.extend([np.sum(itemgetter(*idx)(ddata))])#extend gain list with forest gain columns from csvif"gain"in f and f.startswith(uni):
myfile =os.path.join(folder, f)print"Doing %s" % myfile
_, ddata = read_me(myfile)for u in unique_id:
idx = np.where(np.array(idd)==u)[0]
gain.extend([np.sum(itemgetter(*idx)(ddata))])#create the table with id, area, gain and loss
big_table = np.ones([len(id),4])
big_table[:,0]=id
big_table[:,1]= area
big_table[:,2]= gain
big_table[:,3]= loss
#write data out to csv file
outfile = folder + "/ecoregion_forest_tot.csv"print"Writing out to %s" %outfile
np.savetxt(outfile, big_table, fmt="%.0f, %.12f, %.12f, %.12f", delimiter=',')return#change the folder containing ecoregion csv files
folder ='/Users/lucabattistella/Downloads/ECOREGION_FOREST/'
do_all(folder)
Global Forest Change Ecoregion Statistics
The provided code has been used to generate data at the Ecoregion level for the Digital Observaty for Protected Areas
The script uses Hansen et al. (2013) Global Forest Change map in conjunction with Google Earth Engine to calculate forest cover in years 2000 - 2012 for a given Ecoregion or Country
Global Forest Change map
GFC map is composed of several bands (layers). Each layer is a separate image that represents a different piece of information. Here we will focus on four of them:
treecover2000: percentage of tree cover in the pixel. In other words, each pixel has value from 0 till 100, with 0 meaning no forest at all and 100 full forest cover
loss: pixel has value 1 if loss ever occurred during the study period.
gain: pixel has value 1 if gain ever occurred during the study period.
lossyear: value of a pixel denotes in which year loss occurred, starting with 2000. In other words, if pixel has value 5, then it means that the deforestation event occurred in 2005.
Ecoregion statistics using GEE
Countries statistics using GEE